package enumdemo_0406;

public enum TestEnum {
    RED(0,"RED"), GREEN(1,"WHITE"), BLUE(2,"BLUE");
    public int ordinal;
    public String color;
    TestEnum(int ordinal, String color) {
        this.ordinal = ordinal;
        this.color = color;
    }

    public static void main(String[] args) {
        //枚举对象转数组
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
                                                     //获得枚举对象对应值
            System.out.println(testEnums[i] + " " + testEnums[i].ordinal());
        }
        System.out.println("=======");
        //将字符串转换为对应的枚举对象（原有的）
        TestEnum testEnum = TestEnum.valueOf("BLUE");
        System.out.println(testEnum);
        System.out.println(RED.compareTo(BLUE));

    }
    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.RED;
        switch (testEnum) {
            case RED:
                System.out.println("红色");
                break;
            case GREEN:
                System.out.println("绿色");
                break;
            case BLUE:
                System.out.println("蓝色");
                break;
        }


    }
}
